Vue.directive('jgGrid',
$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'operation/bookShelf/list',
        datatype: "json",
        colModel: [			
			{ label: '书柜编号', name: 'code',index:"rfid_code",width:100,align:'center' },
			{ label: '型号', name: 'bookName',index:"book_name" ,width:80,align:'center' },
			{ label: '投放地址', name: 'cashAddress', index:"price",width:180 ,align:'center'},
			{ label: '投放时间', name: 'createTime',index:"isbn_no",width:140 ,align:'center' },
			{ label: '上次维护时间', name: 'putonDate',index:"puton_date" ,width:130 ,align:'center'},
			{ label: '书籍投放数量', name: 'originalCount',index:"borrow_time_start",width:100 ,align:'center'},
			{ label: '书籍实际数量', name: 'currentCount',index:"borrow_time_end",width:100,align:'center' },
			{ label: '书籍在借数量', name: 'borrowedCount',index:"book_borrow_count",width:100,align:'center'},
			{ label: '书格正常数量', name: 'disparkCount',index:"dispark_count",width:100,align:'center',
				formatter:function(cellvalue, options, rowObject){
					return (rowObject.bookGridCount - rowObject.disparkCount)+"/"+rowObject.bookGridCount;
				}
			},
			{ label: '书柜状态', name: 'damageReport',index:"dispark_count",width:80,align:'center',
				formatter:function(cellvalue, options, rowObject){
					if(rowObject.damageReport==1){
						return "维护";
					}else{
						if(rowObject.disparkCount==8){
							return "维护";
						}else if(0<rowObject.disparkCount&&rowObject.disparkCount<8){
							return "部分维护";
						}else{
							return "正常";
						}
					}
				}
			},
			{ label: '操作', name: '操作',
				formatter:function(cellvalue, options, rowObject){
					return "<a onclick=\"bookShelfStatusHtml('"+rowObject.code+"')\">书柜维护</a> <a  onclick=\"bookShelfOpenHtml('"+rowObject.code+"')\">手动开柜</a> <a  onclick=\"bookShelfMonitoringHtml('"+rowObject.code+"')\">书柜详细</a>";
				},index:"comment_count",width:190,align:'center' 
			},
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [5,10,20],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        autoScroll:true,
        shrinkToFit:false,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        
    });
}));


var vm = new Vue({
	el:'#rrapp',
	data:{
		q:{
			bookName: null,
			rfidCode: null,
			bookBorrowStartTimeA: null,
			bookBorrowStartTimeB: null,
			bookBorrowEndTimeA: null,
			bookBorrowEndTimeB: null
		},
		showList: true,
		title: null
	},
	methods: {
		query: function () {
			vm.reload();
		},
		bookShelfStatusLayer: function(code) {
			layer.open({
				type : 2,
				title : '书柜维护管理',
				closeBtn: 1,
				maxmin : true,
				shadeClose : true, // 点击遮罩关闭层
				area : [ '450px', '300px' ],
				content : ['./book-shelf-manager.html?code='+code,'no']
			});
		},
		bookShelfOpenLayer: function(code) {
			layer.open({
				type : 2,
				title : '手动开柜页面',
				closeBtn: 1,
				maxmin : true,
				shadeClose : true, // 点击遮罩关闭层
				area : [ '550px', '500px' ],
				content : ['./book-shelf-open.html?code='+code,'no']
			});
		},
		bookShelfMonitoringLayer: function(code){
			layer.open({
				type : 2,
				title : '书籍监控页面',
				closeBtn: 1,
				maxmin : true,
				shadeClose : true, // 点击遮罩关闭层
				area : [ '800px', '700px' ],
				content : ['./book-shelf-monitoring.html?code='+code,'no']
			});
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam', {
				postData : {
					'bookName' : vm.q.bookName,
					'rfidCode' : vm.q.rfidCode,
					'bookBorrowStartTimeA' : vm.q.bookBorrowStartTimeA,
					'bookBorrowStartTimeB' : vm.q.bookBorrowStartTimeB,
					'bookBorrowEndTimeA' : vm.q.bookBorrowEndTimeA,
					'bookBorrowEndTimeB' : vm.q.bookBorrowEndTimeB
				},
				page : page
			}).trigger("reloadGrid");
		}
	}
});